package com.iwdnb.gkgz.common.model.dto;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import com.iwdnb.gkgz.common.utils.BigDecimalUtils;
import com.iwdnb.gkgz.common.utils.EmotionAnalysis;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;

@Data
public class StockEmotion implements Serializable {
    private static final long serialVersionUID = 1L;
    private String datetime;

    private int open;

    private int close;

    private List<StockEmotion> list;

    private List<StockEmotion> rangeList;

    /**
     * 标识情绪
     */
    private int markEmotion;
    /**
     * 情绪数值
     */
    private BigDecimal currentValue;

    private BigDecimal minValue;

    private BigDecimal lowValue;

    private BigDecimal highValue;

    private BigDecimal maxValue;

    public void addEmotion(StockEmotion stockEmotion, int markEmotion) {
        if (CollectionUtils.isEmpty(list)) {
            list = new ArrayList<>();
            rangeList = new ArrayList<>();
        }
        //特殊处理,markEmotion==1时，且当前均涨幅比开盘高1个点,更改markEmotion
        //if (markEmotion == 1 && EmotionAnalysis.isColdEmotion(markEmotion) && CollectionUtils.isNotEmpty(list)) {
        //    StockEmotion openEmotion = list.get(0);
        //    if (Objects.nonNull(openEmotion)) {
        //        BigDecimal rate = BigDecimalUtils.subtract(stockEmotion.getCurrentValue(),
        //            openEmotion.getCurrentValue());
        //        if (BigDecimalUtils.isGe(rate, BigDecimal.ONE)) {
        //            markEmotion = 7;
        //            stockEmotion.setMarkEmotion(markEmotion);
        //        }
        //    }
        //}
        this.markEmotion = markEmotion;
        stockEmotion.setMarkEmotion(markEmotion);
        list.add(stockEmotion);
        if (!rangeList.isEmpty()) {
            int emotion = rangeList.get(rangeList.size() - 1).getClose();
            if (emotion != stockEmotion.getClose()) {
                rangeList.add(stockEmotion);
            }
        } else {
            rangeList.add(stockEmotion);
        }
    }
}
